package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;
/**
 * Created by xuzhi on 2016/10/11.
 */
public class UserDefined implements WorkInterFace{
    @Override
    public String getName() {
        return "用户自定义返回结果";
    }

    @Override
    public String getDesciption() {
        return "";
    }

    @Override
    public int getVersion() {
        return 0;
    }

    @Override
    public Attr[] getInAttrs() {
        Attr[] in = new Attr[6];
        in[0] = new Attr("inlog", "自定义输出参数1", AttrType.TYPE_String, true);
        in[1] = new Attr("inlogname", "自定义输出参数1名称", AttrType.TYPE_String, true);

        in[2] = new Attr("inlog2", "自定义输出参数2", AttrType.TYPE_String, true);
        in[3] = new Attr("inlogname2", "自定义输出参数2名称", AttrType.TYPE_String, true);

        in[4] = new Attr("inlog3", "自定义输出参数3", AttrType.TYPE_String, true);
        in[5] = new Attr("inlogname3", "自定义输出参数3名称", AttrType.TYPE_String, true);
        return in;
    }

    @Override
    public Attr[] getOutAttrs() {
        Attr[] out = new Attr[2];
        out[0] = new Attr("log", "日志输出", AttrType.TYPE_String, true);
        out[1] = new Attr("show", "日志输出", AttrType.TYPE_String, true);
        return out;
    }

    @Override
    public Map<String, Object> init(Map<String, Object> data) {
        Map<String, Object> outmap = new HashMap<String, Object>();
        String inlog=String.valueOf( data.get("inlog"));
        String inlogname=String.valueOf(data.get("inlogname"));
        String inlog2=String.valueOf(data.get("inlog2"));
        String inlogname2=String.valueOf(data.get("inlogname2"));
        String inlog3=String.valueOf(data.get("inlog3"));
        String inlogname3=String.valueOf( data.get("inlogname3"));


        StringBuffer show = new StringBuffer();
        if (StringUtils.isNotBlank(inlog)&&!inlog.equals("null")){
            if(StringUtils.isNotBlank(inlogname)&&!inlogname.equals("null")){
                show.append(inlogname+":"+inlog+"<br>");
            }else {
                show.append(inlog+"<br>");
            }
        }

        if (StringUtils.isNotBlank(inlog2)&&!inlog2.equals("null")){
            if(StringUtils.isNotBlank(inlogname2)&&!inlogname2.equals("null")){
                show.append(inlogname2+":"+inlog2+"<br>");
            }else {
                show.append(inlog2+"<br>");
            }
        }

        if (StringUtils.isNotBlank(inlog3)&&!inlog3.equals("null")){
            if(StringUtils.isNotBlank(inlogname3)&&!inlogname3.equals("null")){
                show.append(inlogname3+":"+inlog3+"<br>");
            }else {
                show.append(inlog3+"<br>");
            }
        }

        if(show.length()>0){
            outmap.put("log",show.toString());
            outmap.put("show",show.toString());
        }else {
            outmap.put("log","自定义节点无输入参数");
            outmap.put("show","自定义节点无输入参数");
        }
        return outmap;
    }
}
